package be.vdab.servlets;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import be.vdab.dao.SausenDAO;

/**
 * Servlet implementation class SausenZoeken
 */
@WebServlet("/ingedrienten.htm")
public class IngedrientenZoekenServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String VIEW = "/WEB-INF/JSP/ingedrientenZoeken.jsp";
	private final SausenDAO sausenDAO = new SausenDAO();

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if(!request.getParameterMap().isEmpty()) {
			Map<String, String> fouten = new HashMap<String, String>();
			String ingedrient=null;
			
				ingedrient= request.getParameter("ingedrient");
			if (ingedrient.isEmpty()) {
				fouten.put("ingedrient", "Verplicht");
			}
			if (fouten.isEmpty()) {
				request.setAttribute("sausen", sausenDAO.findIngedrient(ingedrient));
			}
			request.setAttribute("fouten", fouten);
		}
		RequestDispatcher dispatcher= request.getRequestDispatcher(VIEW);
		dispatcher.forward(request, response);
	}

}
